﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Interop.Word;

namespace WFL.Office.Word
{
    public class WordHyperlinks : IEnumerable<WordHyperlink>
    {
        public WordHyperlink this[int index]
        {
            get { return new WordHyperlink(_hyperlinks[index]); }
        }

        public WordHyperlink this[string index]
        {
            get { return new WordHyperlink(_hyperlinks[index]); }
        }

        private Hyperlinks _hyperlinks;

        public WordDocument Document
        {
            get;
            internal set;
        }

        internal WordHyperlinks(Hyperlinks hyperlinks)
        {
            _hyperlinks = hyperlinks;
        }

        public WordHyperlink Add(object anchor, string address = null, string subAddress = null, string screenTip = null, string textToDisplay = null, string target = null)
        {
            object addressArg = address ?? Type.Missing;
            object subAddressArg = subAddress ?? Type.Missing;
            object screenTipArg = screenTip ?? Type.Missing;
            object textToDisplayArg = textToDisplay ?? Type.Missing;
            object targetArg = target ?? Type.Missing;
            return new WordHyperlink(_hyperlinks.Add(anchor, addressArg, subAddressArg, screenTipArg, textToDisplayArg, targetArg));
        }


        #region IEnumerable<WordHyperlink> 成员

        public IEnumerator<WordHyperlink> GetEnumerator()
        {
            foreach (Hyperlink hyperlink in _hyperlinks)
            {
                yield return new WordHyperlink(hyperlink);
            }
        }

        #endregion

        #region IEnumerable 成员

        IEnumerator IEnumerable.GetEnumerator()
        {
            foreach (Hyperlink hyperlink in _hyperlinks)
            {
                yield return new WordHyperlink(hyperlink);
            }
        }

        #endregion

    }
}
